home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / rexx / smacros.lha / FWMacros / Create_BarGraph.arexx < prev    next >
Text File  |  1994-12-17  |  8KB  |  312 lines

  1. /* Create_BarGraph
  2. A Macro by Steven. R. Giovenella, 5823 Dutchess Dr., Colorado Springs, CO 80918.
  3. © Copyright 1994 Steven. R. Giovenella, All rights reserved. 
  4. This macro is my gift to the Amiga community.  It may be given away free to 
  5. anyone, but it may NOT be sold in any way, shape, or form, not even for the cost of 
  6. reproduction, downloading, shipping, or handling, without express written 
  7. permission from the author listed above.  Any person or company who violates the 
  8. content of the previous sentence, agrees to pay Steven R. Giovenella $1,000 (US) for 
  9. each copy of this macro sold.  This macro may NOT be added to any disk which is to 
  10. be sold for any price or fee, to include shipping and handling.  The ONLY way this 
  11. macro may be distributed is on a disk which is given away 100% free of all charges, 
  12. or on via telecommunications networks which do not charge any additional fee as a 
  13. result of a user downloading this particular macro.  This macro may only be 
  14. reproduced in its entirety, including all comment lines and code.  The individual 
  15. user may alter this macro for personal use, but may not then distribute the macro 
  16. in any modified form.  If you wish, feel free to send me some cash, a Christmas card, 
  17. some other piece of software, or absolutely nothing as a gift for creating this macro.  
  18. The author of this software is not responsible for any data loss or damage to 
  19. computer equipment as a result, direct or indirect, of the use of this macro. */
  20.  
  21. Options Results
  22.  
  23. /****************************/
  24. /* Ask questions */
  25.  
  26.     /* Warning */
  27.     Showmessage 2 0 '"                                   ** WARNING **" "            This Macro 
  28. will alter the current document." "Unless the document is empty, save before 
  29. proceeding." "      Proceed     " "      Save now        " "    Quit    "'
  30.         IF Result = 2 THEN SaveAs
  31.         IF Result = 3 THEN Exit
  32.  
  33.     ShowMessage 1 0 '"Select border option..." "" "" "    2 pts    " "    1 pt    " "   
  34. None     "'
  35.         IF Result = 1 THEN border = 2
  36.         IF Result = 2 THEN border = 1
  37.         IF Result = 3 THEN border = None
  38.     ShowMessage 1 0 '"Select text flow..." "" "" "    Left    " "    Right    " "    None     
  39. "'
  40.         IF Result = 1 THEN tflow = LeftVert
  41.         IF Result = 2 THEN tflow = RightVert
  42.         IF Result = 3 THEN tflow = None
  43.     RequestText '"Create Bar Graph" "Enter maximum value for vertical axis" ""'
  44.         maxY = Result
  45.     RequestText '"Create Bar Graph" "Enter vertical axis increments" ""'
  46.         increment = Result
  47.  
  48. /***********************************************/
  49. /* Data Interpreter */
  50.  
  51.     /* Store current begline and endline */
  52.     Status LinePos
  53.         Coords = Result
  54.         PARSE VAR Coords BegLine BegPos EndLine EndPos
  55.         IF ( EndLine = "" ) THEN DO
  56.             ShowMessage 1 0 '"No Range Selected" "" "" "    OK    " "" ""'
  57.             Exit
  58.             END
  59.     IF EndPos=0 THEN EndLine=EndLine-1
  60.  
  61.     /* Count bars */
  62.     bars = EndLine - BegLine - 2
  63.  
  64.     /* Get Title */
  65.     MoveToLine BegLine 0
  66.     ShiftDown
  67.     CtrlDown
  68.     AltDown
  69.     Cursor right
  70.     Extract
  71.         title.1 = Result
  72.     ShiftUp
  73.     CtrlUp
  74.     AltUp
  75.  
  76.     /* Get Subtitle */
  77.     MoveToLine BegLine+1 0
  78.     ShiftDown
  79.     CtrlDown
  80.     AltDown
  81.     Cursor right
  82.     Extract
  83.         title.2 = Result
  84.     ShiftUp
  85.     CtrlUp
  86.     AltUp
  87.  
  88.     /* Get rest of data */
  89.     /* Add Trailing Spaces */
  90.     DO line = (BegLine+3) to EndLine
  91.         MoveToLine line 0
  92.         CtrlDown
  93.         AltDown
  94.         Cursor right
  95.         type " "
  96.         END
  97.  
  98.     /* Extract Data x.0 and y.0 through x.count and y.count */
  99.     count = 0
  100.     DO line = (BegLine+2) to EndLine
  101.         MoveToLine line 0
  102.         Status ParaChars
  103.             pchars = Result
  104.         DO i=0 to pchars
  105.             MoveToLine line i
  106.             Extract
  107.                 char = Result
  108.             IF char = "    " THEN LEAVE
  109.             END
  110.         MoveToLine line i
  111.         ShiftDown
  112.         CtrlDown
  113.         AltDown
  114.         Cursor left
  115.         Extract
  116.             x.count = Result
  117.         ShiftUp
  118.         MoveToLine line (i+1)
  119.         ShiftDown
  120.         Cursor right
  121.         AltUp
  122.         CtrlUp
  123.         IF line ~= (Begline+2) THEN Cursor left
  124.         Extract
  125.             r = Result
  126.             IF count = 0 THEN y.count = r
  127.                 ELSE DO
  128.                      PARSE VAR r r1
  129.                     y.count = Value('r1')
  130.                 END
  131.         ShiftUP
  132.         CtrlUp
  133.         AltUP
  134.         count = count +1
  135.         END
  136.  
  137. /***********************************************/
  138. /* Draw graph */
  139.  
  140.     /* Get precise coordinates for placing graph */
  141.     /* In order to get scroll position */
  142.     /* Move to end of document */
  143.     CtrlDown
  144.     AltDown
  145.     Cursor Down
  146.     CtrlUP
  147.     AltUp
  148.  
  149.     /* Insert a page break */
  150.     InsertPageBreak
  151.  
  152.     /* Movetoline begline */
  153.     MoveToLine BegLine 0
  154.  
  155.     /* Get scroll position */
  156.     Status ScrollPos
  157.         Coords = Result
  158.         PARSE VAR Coords scrollX scrollY
  159.  
  160.     /* Draw matt */
  161.     BoxPrefs TEXTFLOW tflow LINEWT border FILL solid FILLCOLOR white
  162.     DrawBox 1 1 scrollY 6.5 5.5
  163.         firstobject = Result
  164.  
  165.     /* Draw Grid */
  166.     scaleheight = 2.5 / maxY
  167.     LinePrefs TEXTFLOW none LINEWT hairline LINECOLOR black
  168.     IF increment = 0 THEN CALL skipgrid
  169.     DO i = 1 to TRUNC( maxY / increment)
  170.         ygrid = scrollY + 4.25 - increment * i * scaleheight
  171.         DrawLine 1 2.375 ygrid 7 ygrid
  172.         END
  173.     DrawLine 1 2.375 scrollY+4.25  7 scrollY+4.25
  174.     ygrid = scrollY + 4.25 - maxY * scaleheight
  175.     DrawLine 1 7 ygrid 7 scrollY + 4.25
  176.  
  177.     /* Draw Y Axis Numbers */
  178.     TextBlockTypePrefs SIZE 14 COLOR Black
  179.     DrawTextBlock 1 2 scrollY+4.185 "0"    
  180.     DO i = 1 to maxY / increment
  181.         ypos = ScrollY + 4.185 - (increment * i * scaleheight)
  182.         DrawTextBlock 1 2 ypos increment * i
  183.         END
  184.     
  185. skipgrid:
  186.  
  187.     /* Draw Bars */
  188.     BoxPrefs TEXTFLOW none LINEWT 1 LINECOLOR Black FILL Solid
  189.     barwidth = 3.5 / bars
  190.     largeY= y.1
  191.     DO i=1 to (bars-1)
  192.         nextY = i+1
  193.         largeY = MAX( largeY , y.nextY )
  194.         END
  195.     DO i=1 to bars
  196.         color.1 = 'red'
  197.         q = i - 1
  198.         IF color.q= 'red' THEN color.i = 'yellow'
  199.         IF color.q = 'yellow' THEN color.i = 'magenta'
  200.         IF color.q = 'magenta' THEN color.i = 'green'
  201.         IF color.q = 'green' THEN color.i = 'cyan'
  202.         IF color.q = 'cyan' THEN color.i = 'brown'
  203.         IF color.q = 'brown'  THEN color.i = 'red'
  204.         BoxPrefs FILLCOLOR color.i
  205.         lbox = 3 + (barwidth * i ) - barwidth
  206.         tbox = scrollY + 4.25 - (y.i * scaleheight)
  207.         hbox = y.i * scaleheight
  208.         DrawBox 1 lbox tbox barwidth hbox
  209.         DrawTextBlock 1 lbox (tbox-.2) y.i
  210.         /* position number */
  211.             GetObjectCoords 
  212.                 coords = Result
  213.                 PARSE VAR coords page x1 y1 twidth theight
  214.                 thalf = twidth / 2
  215.                 xpos = x1 - thalf + barwidth/2
  216.                 SetObjectCoords 0 1 xpos tbox-.2 twidth theight
  217.         lline = lbox + barwidth / 2
  218.         IF bars>2 THEN DO
  219.             IF i/2 = TRUNC(i/2) THEN DO
  220.                 DrawLine 1 lline scrollY+4.25 lline scrollY+4.5625
  221.                 END
  222.             END
  223.         DrawLine 1 lline scrollY+4.25 lline scrollY+4.375
  224.         END
  225.     BoxPrefs LINEWT none FILL solid FILLCOLOR white
  226.  
  227.     /* Draw lables */
  228.     /* Title */
  229.     TextBlockTypePrefs SIZE 28 OBLIQUE 2
  230.     DrawTextBlock 1 2 scrollY title.1
  231.         GetObjectCoords 
  232.             coords = Result
  233.             PARSE VAR coords page x1 y1 twidth theight
  234.             thalf = twidth / 2
  235.             xpos = 4.25 - thalf
  236.             SetObjectCoords 0 1 xpos scrollY+.25 twidth theight 
  237.  
  238.     /* SubTitle */
  239.     TextBlockTypePrefs SIZE 20 OBLIQUE 2
  240.     DrawTextBlock 1 2 scrollY title.2
  241.         GetObjectCoords 
  242.             coords = Result
  243.             PARSE VAR coords page x1 y1 twidth theight
  244.             thalf = twidth / 2
  245.             xpos = 4.25 - thalf
  246.             SetObjectCoords 0 1 xpos scrollY+.75 twidth theight     
  247.  
  248.     /* X axis */
  249.     TextBlockTypePrefs SIZE 18 OBLIQUE 0
  250.     DrawTextBlock 1 2.5 scrollY+4.75 x.0
  251.     GetObjectCoords 
  252.         coords = Result
  253.         PARSE VAR coords page x1 y1 twidth theight
  254.         thalf = twidth / 2
  255.         xpos = 4.75 - thalf
  256.         SetObjectCoords 0 1 xpos (scrollY+5) twidth theight
  257.  
  258.     /* Yaxis */
  259.     DO i=1 to LENGTH(y.0)
  260.         yind.i = SUBSTR(y.0 , i , 1)
  261.         END
  262.     TextBlockTypePrefs SIZE 18
  263.     ypos = scrollY + 3 - LENGTH(y.0) / 2 * .2
  264.     DO i=1 to LENGTH(y.0)
  265.         DrawTextBlock 1 1.25 ypos yind.i
  266.         ypos = ypos + .2
  267.         END
  268.  
  269.     /* Draw Bar labels */
  270.     TextBlockTypePrefs SIZE 12 COLOR Black
  271.     DO i=1 to  bars
  272.         labelxpos = 3 + (i * barwidth) - (.5 *barwidth)
  273.         labelypos = scrollY + 4.4
  274.         DrawTextBlock 1 labelxpos labelypos x.i
  275.             lastobject = Result
  276.         GetObjectCoords 
  277.             coords = Result
  278.             PARSE VAR coords page x1 y1 twidth theight
  279.             thalf = twidth / 2
  280.             xpos = labelxpos - thalf
  281.             IF bars>2 THEN DO
  282.                 IF i/2 = TRUNC(i/2) THEN labelypos = labelypos + .2
  283.                 END
  284.             SetObjectCoords 0 1 xpos labelypos twidth theight
  285.         END
  286.  
  287.     /* Draw Axes */
  288.     LinePrefs TEXTFLOW none LINEWT 2 LINECOLOR Black
  289.     ypos = scrollY+4.25
  290.     DrawLine 1 2.5  ypos 7.125 ypos
  291.     DrawLine 1 2.5 ypos 2.5 scrollY+1.58
  292.         lastobject = Result
  293.  
  294.     /* Group all */
  295.     DO i=firstobject to lastobject
  296.         SelectObject i MULTIPLE
  297.         END
  298.     Group
  299.  
  300. /***********************************************/
  301. /* Clean up */
  302.  
  303.     /* Remove extra page */
  304.     CtrlDown
  305.     AltDown
  306.     Cursor Down
  307.     Backspace
  308.     MoveToLine Begline 0
  309.     
  310. Redraw
  311.  
  312.